home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / mail / YAMscripts.lha / RemDupl.rexx < prev    next >
OS/2 REXX Batch file  |  1997-06-29  |  2KB  |  106 lines

  1. /* RemDupl 1.2 - 27-Jun-97
  2. **
  3. ** This version checks the message text instead of the headers!
  4. **
  5. ** NOTE: You *MUST* set Configuration/Folder 'Delete messages on exit'
  6. **       on or the script might delete wrong messages!  That also lets
  7. **       you to undelete messages if something goes wrong.
  8. */
  9. options results
  10. call addlib('rexxsupport.library',0,-30,0)
  11. limit=25    /* If the difference in file sizes is less than limit, the message */
  12.         /* contents are checked */
  13.  
  14. address 'YAM'
  15. 'MailUpdate'
  16. 'GetFolderInfo Max'
  17. num=result
  18.  
  19. do m=0 to num-1
  20.     'SetMail' m
  21.     'GetMailInfo File'
  22.     file.m=result
  23.     info=statef(result)
  24.     parse var info type bytes .
  25.     size.m=bytes
  26.     msg.m=m
  27. end /* do m */
  28. size.num=9999999
  29.  
  30. call Sort(0,num-1)
  31.  
  32. dc=0
  33. do m=0 to num-2
  34.     i=m+1
  35.     'SetMail' msg.m
  36.     NotDeleted=1
  37.     do while size.i-size.m<limit & NotDeleted & i<num
  38.         if are_same(i,m) then do
  39.             'MailDelete'
  40.             NotDeleted=0
  41.             end
  42.         i=i+1
  43.         end
  44.     end
  45. exit
  46.  
  47. are_same: procedure expose file. 
  48. parse arg i,j
  49. if open(1,file.i,'r') & open(2,file.j,'r') then do
  50.     call SkipHeaders(1)
  51.     call SkipHeaders(2)
  52.     res=1
  53.     do while res & ~eof(1) & ~eof(2)
  54.         res=(readln(1)=readln(2))
  55.         end
  56.     end
  57. else
  58.     res=0
  59. call close(1)
  60. call close(2)
  61. return res
  62.  
  63. SkipHeaders: procedure
  64. parse arg f
  65.     do until r='' | eof(f)
  66.         r=readln(f)
  67.         end
  68. return
  69.  
  70. Sort: procedure expose size. file. msg.
  71. parse arg p,r
  72. if p<r then do
  73.     q=Partition(p,r)
  74.     Call Sort(p,q)
  75.     Call Sort(q+1,r)
  76.     end
  77. return
  78.  
  79. Partition: procedure expose size. file. msg.
  80. parse arg p,r
  81. x=size.p
  82. i=p-1
  83. j=r+1
  84. do while 1
  85.     do until size.j<=x
  86.         j=j-1
  87.         end
  88.     do until size.i>=x
  89.         i=i+1
  90.         end
  91.     if i<j then do
  92.         t=size.j
  93.         size.j=size.i
  94.         size.i=t
  95.         t=file.j
  96.         file.j=file.i
  97.         file.i=t
  98.         t=msg.j
  99.         msg.j=msg.i
  100.         msg.i=t
  101.         end
  102.     else
  103.         return j
  104.     end
  105.  
  106.